#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Book {
    char name[50];
    double price;
};

int main() {
    int n;
    scanf("%d", &n);

    struct Book book[10];

    for (int i = 0; i < n; i++) {
    	getchar();
        gets(book[i].name);
        scanf("%lf", &book[i].price);
    }

    int max = 0, min = 0;

    for (int i = 1; i < n; i++) {
        if ((book[i].price > book[max].price)&&(book[i].price!=0))
        {
        	max=i;
		}
        

        if ((book[i].price < book[min].price)&&(book[i].price!=0)) {
            min = i;
        }
    }

    printf("%.2lf, %s\n", book[max].price, book[max].name);
    printf("%.2lf, %s", book[min].price, book[min].name);

    return 0;
}
